/**
 * 小程序配置文件 
 */
let isOnline = true; //环境类型
let LOGIN_KEY = 'LOGIN_KEY'; //登录缓存信息KEY
let LOGIN_INFO = null; //登录用户信息
let hostUrl = ""; //接口服务器
let hostUrl01 = ""; //部分接口服务器
let hostUrl02 = ""; //部分接口服务器
let playUrl = ""; //视频回放服务器
let socketUrl = ""; //聊天服务器
let logUrl = ""; //错误日志服务器
/** 正式环境 **/
if (isOnline) {
  hostUrl = 'https://liveapi.huachuangshidai.com';
  hostUrl01 = 'https://webapi02.huachuangshidai.com';
  hostUrl02 = 'https://emq.huachuangshidai.com';
  playUrl = "https://dvrhw.huachuangshidai.com";
  socketUrl = "wss://chat.huachuangshidai.com/ws";
  logUrl = "https://log.huachuangshidai.com";
}else{
  // hostUrl = 'http://192.168.3.5:811';
  // hostUrl02 = 'http://192.168.3.5:811';
  // playUrl = "http://192.168.3.5:811";

  hostUrl = 'http://192.168.3.5:5001';
  hostUrl02 = 'http://192.168.3.5:5001';
  playUrl = "http://192.168.3.5:5001";

  socketUrl = "wss://chat.huachuangshidai.com/ws";
  logUrl = "https://log.huachuangshidai.com";
}

let config = {
    hostUrl,
    playUrl,
    socketUrl,
    logUrl,
    LOGIN_KEY,
    APP_NAME: '华创时代',
    APP_VERSION: '2.1.2',
    APP_ID: 'wx64b438c07d5ced1d',
    //openId
    OPENID: function () {
      return LOGIN_INFO && LOGIN_INFO.OPENID ? LOGIN_INFO.OPENID : "";
    },
    //token
    TOKEN: function () {
      return LOGIN_INFO && LOGIN_INFO.TOKEN ? LOGIN_INFO.TOKEN : "";
    },
    //用户头像
    HEADURL: function () {
        return LOGIN_INFO && LOGIN_INFO.HEADURL ? LOGIN_INFO.HEADURL : "";
    },
    // 用户昵称
    NICKNAME: function () {
        return LOGIN_INFO && LOGIN_INFO.NICKNAME ? LOGIN_INFO.NICKNAME : "";
    },
    // 用户名称
    NAME: function () {
        return LOGIN_INFO && LOGIN_INFO.NAME ? LOGIN_INFO.NAME : "";
    },
    // 用户手机号
    TEL: function () {
      return LOGIN_INFO && LOGIN_INFO.TEL ? LOGIN_INFO.TEL : "";
    },
    // 角色身份
    ROLE: function () {
      return LOGIN_INFO && LOGIN_INFO.ROLE ? LOGIN_INFO.ROLE : "";
    },
    //用户id
    UID: function(){
      return LOGIN_INFO && LOGIN_INFO.UID ? LOGIN_INFO.UID : "";
    },
    
    /** 登录状态 */
    isLogin: function(){
      return config.OPENID() && config.TEL()?true:false
    },

    //获取登录用户缓存信息
    getLoginInfo: function () {
      try {
        let value = wx.getStorageSync(LOGIN_KEY);
        LOGIN_INFO = value ? value : "";
        // console.log("登录信息：", LOGIN_INFO)
      } catch (e) {
        console.log("未获取到登录信息")
      }
    },
    //更新用户缓存信息
    setLoginInfo: function(key,value){
      let user = wx.getStorageSync(LOGIN_KEY);
      switch (key) {
        case "OPENID":
          user.OPENID = value;
          break;
        case "TOKEN":
          user.TOKEN = value;
          break;
        case "HEADURL":
          user.HEADURL = value;
          break;
        case "NAME":
          user.NAME = value;
          break;
        case "NICKNAME":
          user.NICKNAME = value
          break;
        case "TEL":
          user.TEL = value
          break;
        case "ROLE":
          user.ROLE = value
          break;
        case "UID":
          user.UID = value
          break;
        default:
          break;
      }
      wx.setStorageSync(LOGIN_KEY, user);
      config.getLoginInfo();
    },
    
    apiHost: `${hostUrl}/api/`,
    apiHost01: `${hostUrl01}/api/`,
    apiHost02: `${hostUrl02}/api/`,
};

module.exports = config